package classes;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;

/**
 * Data access object (DAO) for domain model class Rayon.
 * 
 * @see classes.Rayon
 * @author MyEclipse Persistence Tools
 */

public class RayonDAO extends BaseHibernateDAO {
	private static final Log log = LogFactory.getLog(RayonDAO.class);

	// property constants
	public static final String NOM = "nom";

	public static final String REFERENCE = "reference";

	public void save(Rayon transientInstance) {
		log.debug("saving Rayon instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(Rayon persistentInstance) {
		log.debug("deleting Rayon instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Rayon findById(java.lang.Integer id) {
		log.debug("getting Rayon instance with id: " + id);
		try {
			Rayon instance = (Rayon) getSession().get("classes.Rayon", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(Rayon instance) {
		log.debug("finding Rayon instance by example");
		try {
			List results = getSession().createCriteria("classes.Rayon").add(
					Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Rayon instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from Rayon as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByNom(Object nom) {
		return findByProperty(NOM, nom);
	}

	public List findByReference(Object reference) {
		return findByProperty(REFERENCE, reference);
	}

	public List findAll() {
		log.debug("finding all Rayon instances");
		try {
			String queryString = "from Rayon";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public Rayon merge(Rayon detachedInstance) {
		log.debug("merging Rayon instance");
		try {
			Rayon result = (Rayon) getSession().merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(Rayon instance) {
		log.debug("attaching dirty Rayon instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Rayon instance) {
		log.debug("attaching clean Rayon instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}